<?php

class Home extends Controller {

	function Home()
	{
		parent::Controller();	
	}
	
	function index() {
		$this->load->helper(array('form', 'url', 'html'));
		$this->load->library('form_validation');
		$this->load->library('parser');
				
		if ($this->form_validation->run() == FALSE) {
      $data['lastUser']=$this->prunussecurity->getLastUsername();
      $this->load->view('test', $data);
			//$this->load->view('test');
		} else {
      if ( $this->prunussecurity->login ("Administrador","1") ) {
        echo "login ok";
      } else {
        echo "error: " . $this->prunussecurity->resultado;
      }
		}
	}
  
  function test(){
    $this->load->model("PrunusTblUsuarios");
    echo "count=" . $this->PrunusTblUsuarios->countRecords();
    echo "<hr/>";
    echo "list:<br/>";
    $res = $this->PrunusTblUsuarios->listRecords(1);
    foreach ($res->result_array() as $val) {
      foreach ($val as $k=>$v) {        
        echo "  $k : $v  <br />";
      }
    } 

    $usuId = 1;
    
    echo "<hr/>";
    $res = $this->PrunusTblUsuarios->getRecord($usuId);
    echo "get:<br/>";
    foreach ($res->result_array() as $val) {
      foreach ($val as $k=>$v) {        
        echo "  $k : $v  <br />";
      }
    } 
    
    echo "<hr/>";
    $q = $this->PrunusTblUsuarios->getRelacion('roles')->countRecords($usuId);
    $res = $this->PrunusTblUsuarios->getRelacion('roles')->listRecords($usuId);
    echo "Relacion Roles: <Br/>";
    echo "  count: " . $q . " <Br/>";
    foreach ($res->result_array() as $val) {
      foreach ($val as $k=>$v) {        
        echo "  $k : $v  <br />";
      }
    } 
    
    die();
/*
    echo "<hr/>";
    echo "insert:<br/>";
    $resId = $this->PrunusTblUsuarios->insertRecord(array("tst_name"=>"Prueba", "tst_pwdHash"=>"123", "tst_alive"=>1));
    echo "id insertado: " . $resId;
    
    echo "<hr/>";
    $res = $this->PrunusTblUsuarios->getRecord($resId);
    echo "get:<br/>";
    foreach ($res->result_array() as $val) {
      foreach ($val as $k=>$v) {        
        echo "  $k : $v  <br />";
      }
    } 
    
    echo "<hr/>";
    echo "update:<br/>";
    $this->PrunusTblUsuarios->updateRecord($resId,array("tst_name"=>"prueba2"));
    echo "registro modificado";
        
    echo "<hr/>";
    $res = $this->PrunusTblUsuarios->getRecord($resId);
    echo "get:<br/>";
    foreach ($res->result_array() as $val) {
      foreach ($val as $k=>$v) {        
        echo "  $k : $v  <br />";
      }
    } 
    
    echo "<hr/>";
    echo "delete:<br/>";
    $this->PrunusTblUsuarios->deleteRecord($resId);
    echo "registro eliminado logicamente";
        
    echo "<hr/>";
    $res = $this->PrunusTblUsuarios->getRecord($resId);
    echo "get:<br/>";
    foreach ($res->result_array() as $val) {
      foreach ($val as $k=>$v) {        
        echo "  $k : $v  <br />";
      }
    } 

    echo "<hr/>";
    echo "kill:<br/>";
    $this->PrunusTblUsuarios->killRecord($resId);
    echo "registro eliminado fisicamente";
        
    echo "<hr/>";
    echo "truncate:<br/>";
    $this->PrunusTblUsuarios->truncate();
    echo "tabla truncada";
        
    echo "<hr/>";
    die("End"); */
    
    echo $this->prunuslib->whoami();
    echo "<hr />";
    
    if ($this->prunussecurity->logged) {
      echo "logged as " . $this->prunussecurity->usuName . " (" . $this->prunussecurity->usuId . ")</br>";
    } else {
      echo "NOT logged</br>";
    }
    
    echo "<a href='/home/login'>login</a><br/>";
    echo "<a href='/home/logout'>logout</a><br/>";
  }
  
  function login() {
    $this->prunussecurity->login("Administrador","1");
    if ($this->prunussecurity->logged) {
      echo "logged as " . $this->prunussecurity->usuName . " (" . $this->prunussecurity->usuId . ")</br>";
    } else {
      echo "NOT logged</br>";
    }
    echo "<a href='/home/test'>test</a>";
  }
  
  function logout() {
    $this->prunussecurity->logout();
    echo "<a href='/home/test'>test</a>";
  }
  
}


/* End of file home.php */
/* Location: ./system/application/controllers/home.php */